from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
import time

d = webdriver.Chrome()
d.get("https://www.baidu.com")

d.maximize_window()

# 鼠标悬停到设置上
sz_ele = d.find_element(By.CSS_SELECTOR, '[id="s-usersetting-top"]')
ActionChains(d).move_to_element(sz_ele).perform()
time.sleep(3)

# 点击搜索设置
ss_ele = d.find_element(By.CSS_SELECTOR, '[class="setpref first"] span')
ss_ele.click()
time.sleep(2)

# 点击保存设置
bc_ele = d.find_element(By.CSS_SELECTOR, '[class="prefpanelgo setting-btn c-btn c-btn-primary"]')
bc_ele.click()
time.sleep(2)

# 警告框处理  switch_to.alert
msg = d.switch_to.alert.text  # 获取警告框的文本
# d.switch_to.alert.dismiss()  # 关闭警告框
d.switch_to.alert.accept()  # 确认警告框
